package com.cloudkinto.cron;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.cloudkinto.common.RedisKeyConstants;
import com.cloudkinto.entity.ClaimDo;
import com.cloudkinto.entity.ProductStockRackDo;
import com.cloudkinto.entity.StorageLocationDo;
import com.cloudkinto.enumType.claim.ClaimStatusEnum;
import com.cloudkinto.service.mail.MailService;
import com.cloudkinto.service.order.claim.ClaimService;
import com.cloudkinto.service.order.outbound.OutboundService;
import com.cloudkinto.service.platform.*;
import com.cloudkinto.service.platform.qoo10.PlatformOrderQoo10Service;
import com.cloudkinto.service.stock.ProductStockRackService;
import com.cloudkinto.service.stock.ProductStockService;
import com.cloudkinto.service.storage.StorageLocationService;
import jdk.nashorn.internal.runtime.logging.Logger;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.stream.Collectors;


/**
 * @author zhangyy
 * @date 2020/6/18 16:03
 * @description: 生产环境下的定时任务
 */
@ConditionalOnProperty(prefix = "gbc", name = "scheduling", havingValue = "sync")
@Component
@RequiredArgsConstructor
@Logger
public class CronSyncService {
    private final RedisTemplate redisTemplate;
    private final PlatformOrderRakutenSyncService platformOrderRakutenSyncService;
    private final PlatformOrderService platformOrderService;


    /**
     * 每天凌晨 重置同步时间
     */
    @Scheduled(cron = "10 0 2 * * ?")
    public void resetRedisSyncTime() {
        platformOrderService.resetRedisSyncTime(false);
    }

    /**
     * 自动标发
     */
    @Scheduled(cron = "50 58 * * * ?")
    public void platformOrderAutoMarkShip() {
        platformOrderService.autoMarkShip();
    }
//    @Scheduled(cron = "40 10 0 * * ?")
//    public void rakutenGetItemList() {
//        platformOrderRakutenSyncService.itemSearch();
//    }
//
//    @Scheduled(cron = "40 20 0 * * ?")
//    public void rakutenGetInventoryList() {
//        platformOrderRakutenSyncService.inventoryGet();
//    }

    /**
     * 定时同步乐天标发状态
     */
    @Scheduled(cron = "20 03,43 * * * ?")
//    @Scheduled(fixedRate = 1000 * 60 * 10)
    public void syncMarkRecordRakuten() {
        platformOrderRakutenSyncService.syncMarkRecord();
    }

    /**
     * 自动确认乐天100订单
     */
//    @Scheduled(cron = "0 18,48 * * * ?")
    @Scheduled(fixedRate = 1000 * 60 * 20)
    public void platOrderAutoConfirm() {
        platformOrderRakutenSyncService.platOrderAutoConfirm();
    }


    /**
     * 自动同步乐天订单
     */
    @Scheduled(cron = "0 18,38,58 * * * ?")
//    @Scheduled(fixedRate = 1000 * 60 * 60 * 8)
    public void rakutenOrderSync() {
        platformOrderRakutenSyncService.platOrderRakutenSync();
    }

}